package com.msl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.msl.R;
import com.msl.bean.AbSyBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SyAdapter extends BaseAdapter {

    private Context mContext;
    LayoutInflater inflater;
    List<AbSyBean.DataBean.ListBean> mlists = new ArrayList<AbSyBean.DataBean.ListBean>();
    private int selectedPosition = 0;// 选中的位置

    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }

    public SyAdapter(Context context, List<AbSyBean.DataBean.ListBean> lists) {
        this.mContext = context;
        inflater = LayoutInflater.from(context);
        mlists = lists;
    }


    @Override
    public int getCount() {
        return mlists == null ? 0 : mlists.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_sy, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv1.setText(mlists.get(position).getDoTime());
        viewHolder.tv2.setText("单号:"+mlists.get(position).getBillCode());
        viewHolder.tv3.setText("由:"+mlists.get(position).getSourceStoreName());
        viewHolder.tv4.setText("发往:"+mlists.get(position).getDesDealerOrStoreName());
        if(position==mlists.size()-1)
        {
            viewHolder.tv1.setTextColor(mContext.getResources().getColor(R.color.redColortext));
            viewHolder.tv2.setTextColor(mContext.getResources().getColor(R.color.redColortext));
            viewHolder.tv3.setTextColor(mContext.getResources().getColor(R.color.redColortext));
            viewHolder.tv4.setTextColor(mContext.getResources().getColor(R.color.redColortext));
            viewHolder.iv.setImageResource(R.mipmap.gi);
        }
        else{
            viewHolder.tv1.setTextColor(mContext.getResources().getColor(R.color.black));
            viewHolder.tv2.setTextColor(mContext.getResources().getColor(R.color.black));
            viewHolder.tv3.setTextColor(mContext.getResources().getColor(R.color.black));
            viewHolder.tv4.setTextColor(mContext.getResources().getColor(R.color.black));
            viewHolder.iv.setImageResource(R.mipmap.ci);
        }
        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.tv1)
        TextView tv1;
        @Bind(R.id.iv)
        ImageView iv;
        @Bind(R.id.tv2)
        TextView tv2;
        @Bind(R.id.tv3)
        TextView tv3;
        @Bind(R.id.tv4)
        TextView tv4;
        @Bind(R.id.llp)
        LinearLayout llp;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}

